<template>
  <div class="room-content">
    <Navbar :appTitle="title" :rtitle="rtitle" :rname="rname" />
    <Search
      ref="topSearch"
      class="search"
      placeholder="工单编号|生产物料|批次编号"
      :isAdd="false"
      :isScreen="true"
      :isType="true"
      @onSearch="onSearch"
      @onScreen="onScreen"
    ></Search>
    <search-tag
      ref="SearchTag"
      :keyword="keyword"
      @resetCategory="resetCategory"
      @getCategory="getCategory"
      v-show="showSearchTag"
    ></search-tag>

    <!--分页列表 -->
    <div class="listBox" :style="{height: GLOBAL.currentEnvironment ? 'calc(100vh - 0.55rem)' : 'calc(100vh - 1.05rem)'}">
      <pageList
        ref="pageList"
        :minLen="3"
        :checkedShow="checkedShow"
        :operationTxt="operationTxt"
        :columns="columns"
        :listUrl="listUrl"
        @getCheckedValue="getCheckedValue"
        @handleList="handleList"
      />
    </div>
  </div>
</template>

<script>
import Search from "@/components/search";
import SearchTag from "./SearchTag";
import Navbar from "@/components/navBar/navBar_right";
import TabBar from "@/components/TabBar";
import pageList from "@/components/pageList";
export default {
  name: "carRoomList",
  components: { Navbar, TabBar, pageList, Search, SearchTag},
  data() {
    return {
      title: "合格品清单",
      rtitle: "",
      rname: "", //search
      checkedShow: true, //列表是否支持选择
      operationTxt: "申请入库", //选择按钮名称
      listUrl: "/mess/messQualifiedList/list", //列表接口
      columns: {
        titleKey: "goodsName", //标题
        // subtitleKey: "description",//副标题
        content: [
          //内容
          {
            name: "规格",
            key: ["spec"],
          },
          {
            name: "数量",
            key: ["num", "basicUnitText"],
          },
          {
            name: "工单编号",
            key: ["orderCode"],
          },
          {
            name: "展示批次",
            key: ["batchCode", "batchId"],
          },
          {
            name: "操作人",
            key: ["operatorName"],
          },
          {
            name: "提交人",
            key: ["applicantName"],
          },
          {
            name: "提交时间",
            key: ["applyTime"],
          },
        ],
        // labelKey: [], //标签
      },
      showSearchTag: false, 
      keyword: "",
      params: {},
    };
  },
  beforeRouteLeave(to, from, next) {
    let that = this
    switch (true) {
      case that.showSearchTag && !that.$refs.SearchTag.ddthrVisible && !that.$refs.SearchTag.operatorVisible:
        that.showSearchTag = false;
        this.title = '合格品清单'
        next(false)
        break;
      case that.$refs.SearchTag.ddthrVisible || that.$refs.SearchTag.operatorVisible:
        that.$refs.SearchTag.ddthrVisible = false;
        that.$refs.SearchTag.operatorVisible = false;
        this.title = '更多筛选'
        next(false)
        break;
      case !that.showSearchTag:
        next();
        break;
    }
  },
  computed: {},
  mounted() {},
  created() {},
  methods: {
    onSearch(v) {
      this.keyword = v
      this.searchQuery()
    },
    onScreen() {
      console.log("筛选");
      this.keyword = this.$refs.topSearch.value
      this.showSearchTag = true
      this.title="更多筛选"
    },
    resetCategory() {
      this.showSearchTag = false
      // this.$refs.topSearch.value = ''
      // this.keyword = ''
      // this.params = {
      //   status: this.active
      // }
      // this.searchQuery()
    },
    getCategory(p, k) {
      this.params = p
      this.keyword = k
      this.params.status = this.active
      this.showSearchTag = false
      console.log(this.params);
      this.$refs.topSearch.value = k
      this.title="合格品清单"
      this.searchQuery()
    },
    // 获取选择的列表数据
    getCheckedValue(ids, item) {
      if (!ids) {
        this.$toast("请选择数据")
        return
      }
      this.$router.push({
        path: '/workManagement/qualifiedProduct/qualifiedProductForm',
        query: { ids: ids },
      })
    },
    //列表点击事件
    handleList(id, item, type) {
      console.log(id, item, type, "id:列表id,item:列表对象,type:事件名");
    },
    // 加载列表
    getList() {
      // 传1代表从第一条数据开始
      this.$refs.pageList.onLoad(1);
    },
    // 搜索
    searchQuery() {
      // 搜索条件
      let queryParam = {
        ...this.params,
      };
      queryParam.keyword = this.keyword
      this.$refs.pageList.searchQuery(queryParam);
    },
    // 重置
    searchReset() {
      this.$refs.pageList.searchReset();
    },
    goSearch() {
      this.$router.push({ path: "/carRoomPlaneSearch" });
    },
  },
};
</script>
<style lang="scss" scoped>
.room-content {
  height: 100vh;
  overflow-y: scroll;
  .serach {
    height: 0.33rem;
    background: #f2f2f6;
    border-radius: 0rem;
    margin-bottom: 0.16rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    line-height: 0.33rem;
    padding: 0.1rem 0.12rem;
    // border: 1px solid red;
    .placeh {
      font-size: 0.16rem;
      font-family: PingFang SC;
      font-weight: 400;
      color: #888888;
      line-height: 0.23rem;
    }
    .icon {
      width: 0.15rem;
      height: 0.16rem;
    }
  }
  .serach-content {
    // height: 1.52rem;
    background: #ffffff;
    padding: 0 0.16rem 0.16rem 0.16rem;
    .content {
      display: flex;
      .tapbtn {
        // height: 0.23rem;
        // background: #1890ff;
        background: #f2f2f6;
        border-radius: 0.02rem;
        font-size: 0.16rem;
        font-family: PingFang SC;
        font-weight: 500;
        color: #888888;
        line-height: 0.23rem;
        margin-right: 0.12rem;
        text-align: center;
        padding: 0.04rem 0.28rem;
        cursor: pointer;
      }
      .active {
        color: #ffffff;
        background: #1890ff;
      }
    }
  }
}
.listBox {
  height: calc(100vh - 1.05rem);
  overflow-y: auto;
}
/deep/.van-nav-bar {
  z-index: 99!important;
}
</style>